package org.beehoo.web.framework.dao;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.type.EnumType;
import org.springframework.orm.hibernate3.support.ClobStringType;

@MappedSuperclass
@TypeDefs({
	@TypeDef(name = "enumer", typeClass = EnumType.class),
	@TypeDef(name = "clobStringType", typeClass = ClobStringType.class)
})
public abstract class IdEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "C_OID", unique = true, nullable = false)
	@GeneratedValue(generator = "tbIdGenerator")
	@GenericGenerator(name = "tbIdGenerator", strategy = "org.beehoo.web.framework.dao.AutoId")
	protected String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public boolean isNewEntity() {
		return id == null || id.trim().length() == 0 || id.trim().equals("-1");
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(this.getClass().getName()).append(":").append(this.getId());
		return builder.toString();
	}

}
